//
//  AppDelegate.m
//  01-UIView、UIWindow
//
//  Created by QC.L on 16/7/14.
//  Copyright © 2016年 QC.L. All rights reserved.
//

#import "AppDelegate.h"
#import "UIView+Frame.h"
@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
#if 0
    // Override point for customization after application launch.
    //程序组成结构
    //1.main.m 主要实现了程序的正常运行
    //2.AppDelegate 程序的执行者,签订了UIApplicationDelegate(协议方法可选)
    //注意 :AppDelegate就是一个普通的类,只不过签订了协议,才有了很多的方法.
    //3.ViewController 视图控制器,主要负责视图的管理 ,看的见,摸得到
    //4.main.stroyboard(视图管理) LaunchScreen.stroyboard(xcode7以前 LaunchScreen.xib负责启动页)可视化管理
    //5.Assets.xcassets(Image.xcassets xcode7以前) 主要管理图片素材
    //6.info.plist (工程配置文件)
    
    
    //模拟器
    //command + 1~5 改变模拟器大小
    //command + 左/右 横竖屏切换
    
    
    //iOS概述
    //iOS错误写法 IOS
    
    
    //1.UIWindow(程序中只有一个主Window)
    // 1>关闭程序的可视化入口,Main.sb
    // 2>创建主window对象
    //创建 主window,使其大小与屏幕大小一样
    //UIScreen系统的屏幕类
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    // 2.给你创建的窗口填颜色 UIColor 系统的颜色类
    _window.backgroundColor = [UIColor whiteColor];
    // 3.让window成为主窗口,并显示
    [_window makeKeyAndVisible];
    // 4.设置window主窗口
    //xcode7以后必须设置rootViewController,否则在该方法结束时,会崩溃
    _window.rootViewController = [[UIViewController alloc] init];
    
    
    // 3>UIWindow 继承于UIView
    
    // 2.UIView(NSObject相似,是UI阶段的根类,大部分控件继承与UIView)
    // 学习新类
    // 1>新类包含哪些初始化方法
    // 2>包含哪些行为(方法)和特征(属性)
    //创建UIView
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 250, 250)];
    view.backgroundColor = [UIColor greenColor];
    //添加到window上
    [_window addSubview:view];
    
    //遇到UIView的子类,都可以用上述方法创建和显示
    //UIView在屏幕中显示为矩形
    
    //    iOS系统坐标系
    //1.与数学的坐标系不同,Y轴的坐标系向下,原点是屏幕左上角.
    
    //    frame,bounds,center(UIView的属性)
    //1.frame (x,y,width,heigh) 视图在父视图的位置
    //2.bounds (x,y,width,heigh) 视图本身的坐标系
    //bounds x,y修改坐标系影响它的子视图
    //bounds width,height修改本身的大小,会以中心点收缩/扩张
    //bounds 的改变不会改变该视图的位置
    //3.center 中心点
    //    view.center = CGPointMake(50, 50);
    
    //bounds对视图的影响
    //bounds的x,y影响子视图的frame,因为它改变得是它的坐标系.
    //CGrect, CGPoint
    
    NSLog(@"改变前%@",NSStringFromCGRect(view.frame));
    NSLog(@"改变前center%@",NSStringFromCGPoint(view.center));
    view.bounds = CGRectMake(0, 0, 300, 300);
    NSLog(@"改变后%@",NSStringFromCGRect(view.frame));
    NSLog(@"改变后center%@",NSStringFromCGPoint(view.center));
    
    
    UIView *subView = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 40, 40)];
    subView.backgroundColor = [UIColor yellowColor];
    [view addSubview:subView];
    
    // 改变绿色view的大小,变成100
    view.frame = CGRectMake(view.frame.origin.x, view.frame.origin.y, 100, view.frame.size.height);
    //view.frame 是get方法
    //frame.size是结构体
    //oc与c结合,是一个常量
    CGRect rect = view.frame;
    rect.size.width = 100;
    view.frame= rect;   //set方法
    //修改
    view.JH_height =100;

#endif
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    // 2.给你创建的窗口填颜色 UIColor 系统的颜色类
    _window.backgroundColor = [UIColor whiteColor];
    // 3.让window成为主窗口,并显示
    [_window makeKeyAndVisible];
    // 4.设置window主窗口
    //xcode7以后必须设置rootViewController,否则在该方法结束时,会崩溃
    _window.rootViewController = [[UIViewController alloc] init];
    
    
    
    //UIview的基本属性
    UIView *testView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
    [_window addSubview:testView];
    //移除
//    [_window removeFromSuperview];
    //1.背景色
    testView.backgroundColor = [UIColor cyanColor];
    //2.透明度alpha 0.0~1.0默认值1.0
    testView.alpha = 0.2;
    //3.tag标记,默认为0
    testView.tag = 100;
    //根据tag获取对应view   __kindof
    UIView *view1 = [_window viewWithTag:100];
    //4.subViews 子视图们
    UIView *arrView = [_window.subviews objectAtIndex:0];
    NSLog(@"%@",arrView);
    //5.superview 父视图
    //testView.superview;
    //6.hidden 默认值NO
    testView.hidden = YES;
    
    //视图层级
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 100, 100)];
    view.backgroundColor = [UIColor orangeColor];
    UIView *view11 = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
    view11.backgroundColor = [UIColor blackColor];
    UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(150, 150, 100, 100)];
    view2.backgroundColor = [UIColor greenColor];
    
//    [testView addSubview:<#(nonnull UIView *)#>];
    [_window addSubview:view];
    
    
//    [testView insertSubview:<#(nonnull UIView *)#> atIndex:<#(NSInteger)#>];(插入视图,到指定下标)
    NSLog(@"------%@",_window.subviews);
    [_window insertSubview:view11 atIndex:2];
    
    
//    [testView insertSubview:<#(nonnull UIView *)#> aboveSubview:<#(nonnull UIView *)#>];(插入视图,到指定视图之上)
    [_window insertSubview:view2 aboveSubview:view11];
    
    
//    [testView insertSubview:<#(nonnull UIView *)#> belowSubview:<#(nonnull UIView *)#>];
    [_window insertSubview:view2 belowSubview:view11];
    
    //UILable(如果类没有初始化方法,使用父类的初始化方法)
    //负责显示文本
    UILabel *lable = [[UILabel alloc] initWithFrame:CGRectMake(20, 300, 300, 100)];
    lable.backgroundColor = [UIColor yellowColor];
    [_window addSubview:lable];
    //label的属性
    //1.text
    lable.text =@"我是就换个环境,吉林省的附件里的手机发了多少积分来打开手机上电脑文件符合沃日我就发热管一如今你不v         吃大葱和生抽社会从侧后会从我沃尔沃侧卧欧赔付款颇为泼墨潘基文;美女陪我看破畏惧我皮肤为开辟v破无法v发文件盘才弄完叫我农村务农我问";
    //2.textcolor
    lable.textColor = [UIColor purpleColor];
    //3.font 默认值17
    lable.font = [UIFont systemFontOfSize:100];
    //加粗
    lable.font = [UIFont boldSystemFontOfSize:17];
    //4.对齐方式 默认left
    lable.textAlignment = NSTextAlignmentRight;
    //5.numberofline 默认1行,不确定时给值为0;
    lable.numberOfLines = 0;
    
    //UIButton
    //UIButtonTypeSystem系统的按钮类型
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.backgroundColor = [UIColor purpleColor];
    button.JH_x = 100;
    button.JH_y = 410;
    button.JH_width = 100;
    button.JH_height = 40;
    [_window addSubview:button];
    //给button添加事件
    [button addTarget:self action:@selector(handleButton) forControlEvents:6];
    //给button添加文字
    [button setTitle:@"点我呀" forState:UIControlStateNormal];
    [button setTitle
    
    
    //UITextField
    UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(100, 500, 200, 40)];
    textField.backgroundColor = [UIColor clearColor];
    [_window addSubview:textField];
    //1.text 为输入框赋初值
//    textField.text = @"文字";
    textField.textColor = [UIColor blackColor];
    //边缘样式 默认None
//    UITextBorderStyleLine; //有边缘线
//    UITextBorderStyleBezel;
    textField.borderStyle = UITextBorderStyleRoundedRect; //有圆角
    //当text不为空时,placeholder不显示
    textField.placeholder = @"请输入密码";
    //清空
    textField.clearsOnBeginEditing = YES;
    //键盘快捷键command + K;
    //取消textfield的编辑状态
    
    
    
    
    return YES;
}
- (void)handleButton{
    [_window endEditing:YES];
    NSLog(@"我被点了");
}
- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
